package com.itheima.edu.info.manager.day14;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadPoolTest {
    public static void main(String[] args) {
        ThreadPoolExecutor pool=new ThreadPoolExecutor(
                //核心线程数量
                1,
                //最大线程数量
                3,
                //零时线程销毁时间
                30,
                //销毁时间单位为
                TimeUnit.SECONDS,
                //任务队列
                new ArrayBlockingQueue<>(10),
                //创建线程工厂
                Executors.defaultThreadFactory(),
                //拒绝策略
                new ThreadPoolExecutor.AbortPolicy());
        pool.submit(()->{
            for (int i = 0; i < 1000; i++) {
                System.out.println(Thread.currentThread().getName()+"s");
            }
        });
        pool.submit(()->{
            for (int i = 0; i < 1000; i++) {
                System.out.println("s");
            }
        });
        pool.shutdown();
    }
}
